<?php

/* This block displays a list of categories that the user has courses
   belonging to. The category names can be clicked on to reveal/hide
   the user's courses within that category.

   (C) 2010 Pall Thayer and SUNY Purchase College, Purchase, NY
   @license http://www.gnu.org/licenses/gpl.html GNU Public License
*/

require_once($CFG->dirroot.'/blocks/cat_course_list/lib.php');

class block_cat_course_list extends block_base {

    function init() {
		$this->title = get_string('blockname', 'block_cat_course_list');
		$this->version = 2010061701;
	}

	function has_config() {
		return false;
	}

	function get_content() {
		global $THEME, $CFG, $USER;
		
        if ($this->content !== NULL) {
			return $this->content;
		}

        $this->content = new stdClass;
        $this->content->text = '';
        $this->content->icons = array();
        $this->content->footer = '';

        require_once($CFG->dirroot.'/course/lib.php');

	$js_txt = '<script type="text/javascript" src="'.$CFG->wwwroot.'/blocks/cat_course_list/jslib.js"></script>';
        $this->content->text .= $js_txt;
        if($rs = get_my_courses($USER->id)){
			$this->content->text .= new_build_cat($rs, $CFG);
        }
		$this->content->footer = '<a href="'.$CFG->wwwroot.'/course/index.php">'.get_string('allcourses', 'block_cat_course_list').'</a>';

		return $this->content;
	}
}
?>
